<?php
$q=$_GET["q"];
$hint="";
$att=explode(",",$q);
$q=$att[0];
$Access_Type=$att[2];
$NIC_Number=$att[1];
if(strlen($q)>0&&$q!="0")
{
include_once ("../Login/databaseconnection.php");
$arr="";
$nics="";
	if($Access_Type=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
   }
$getque=mysql_query("SELECT * FROM teacher WHERE Shool_Id='$Own_School_Id'");
}
	else if($Access_Type=="Administrator")
{
$getque=mysql_query("SELECT * FROM teacher");
}
if($getque)
{
while($row=mysql_fetch_array($getque))
{
$T_NIC_Number=$row['T_NIC_Number'];
if(empty($nics))
{
$nics='"'.$T_NIC_Number.'"';
}
else
{
$nics=$nics.',"'.$T_NIC_Number.'"';
}
}
}

$getquet=mysql_query("SELECT * FROM training_details WHERE Teacher_NIC in ($nics)");
if($getquet)
{
while($rowte=mysql_fetch_array($getquet))
{
$NIC=$rowte['Teacher_NIC'];
$getname=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC'");
if($rowt=mysql_fetch_array($getname))
{
$Name=$rowt['First_Name'].' '.$rowt['Last_Name'];
$value=substr($Name,0,strlen($q));
if(strcasecmp($value,$q)==0)
{
if($arr=="")
{
$arr=$Name;
}
else
{
$arr=$arr."_".$Name;
}
}
}
}
}
 $array= explode("_",$arr);
for ($i = 0; $i <count($array); $i++) 
{
 $temp =$array[$i];
  if($temp!="")
  {
  $hint=$hint.'<li onClick="fill(\''.$temp.'\');">'.$temp.'</li>';
  }
  $j = $i;
  for ($k = 0; $k <count($array); $k++) 
  {
    if ($k != $j) {
      if ($temp == $array[$k]) 
	  {
        $array[$k]="";
      }
    }
  }
}
}
if($hint=="")
{
$response="No suggestions";
}
else
{
$response=$hint;
}
echo $response;
?>